<template>
  <div class="nav-header">

    <div class="logo">
      <img src="~@/assets/img/main/logo.svg" alt="logo">
      <span>Vue admin</span>
      <el-icon  @click="handleFoldClick" :size="20" class="menu-icon" :class="isFold ? 'unfold' : 'fold'"> <i-ep-fold /></el-icon>
    </div>

    <div class="info">
       <el-avatar
        class="avatar"
        src="http://47.104.85.107:8181/static/img/touxiang.45da85b8.jpg"
      ></el-avatar>
      <el-dropdown>
        <span class="el-dropdown-link">
           <span class="name">{{ name }}</span>
           <el-icon class="el-icon--right"> <i-ep-arrow-down /></el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="handleExitClick">退出系统</el-dropdown-item>
            <el-dropdown-item>个人信息</el-dropdown-item>
            <el-dropdown-item>修改密码</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import useMenuIcon from '../hooks/useMenuIconHook'
import { useStore } from '@/store/index'
import { useRouter } from 'vue-router'
import LocalCache from '@/utils/cache'
export default defineComponent({
  emits: ['foldChange'],
  setup (_, ctx) {
    const [ isFold, handleFoldClick ] = useMenuIcon({ emit: ctx.emit})

    const store = useStore()
    const router = useRouter()
    const name = computed(() => store.state.login.userInfo.name)
    const handleExitClick = () => {
      LocalCache.deleteCache('token')
      router.push('/login')
    }
    return {
      isFold,
      name,
      handleFoldClick,
      handleExitClick
    }
  }
})
</script>

<style scoped lang="less">
.fold {
  transform: rotate(180deg);
}
.nav-header {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .logo {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;

    span {
      font-size: 16px;
    }

    img {
      height: 28px;
      margin: 0 10px;
    }
    .menu-icon {
      font-size: 28px;
      cursor: pointer;
      margin-left: 35px;
    }
  }
  .info {
    display: flex;
    align-items: center;
  }
  .el-dropdown-link {
    color: #fff;
    display: flex;
    align-items: center;
    cursor: pointer;

    .avatar {
      width: 30px;
      height: 30px;
    }
    .name {
      margin-left: 8px;
      margin-right: 8px;
    }
  }
}

</style>
